from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QStackedWidget, QVBoxLayout, QPushButton
import sys
class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.initUI()
    def initUI(self):
        self.central_widget = QWidget()
        self.setCentralWidget(self.central_widget)
        self.layout = QVBoxLayout()
        self.central_widget.setLayout(self.layout)
        self.stacked_widget = QStackedWidget()
        self.layout.addWidget(self.stacked_widget)
        self.button1 = QPushButton("Subwindow 1")
        self.button1.clicked.connect(self.show_subwindow1)
        self.layout.addWidget(self.button1)
        self.button2 = QPushButton("Subwindow 2")
        self.button2.clicked.connect(self.show_subwindow2)
        self.layout.addWidget(self.button2)
        self.subwindow1 = QWidget()
        self.stacked_widget.addWidget(self.subwindow1)
        self.subwindow2 = QWidget()
        self.stacked_widget.addWidget(self.subwindow2)
        self.setWindowTitle("Main Window")
    def show_subwindow1(self):
        self.stacked_widget.setCurrentIndex(0)
    def show_subwindow2(self):
        self.stacked_widget.setCurrentIndex(1)


if __name__ == "__main__":
    app = QApplication(sys.argv)
    main_window = MainWindow()
    main_window.show()
    sys.exit(app.exec_())